<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* brief description of file
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/

-->
<!--

/**
* filename, brief description, date of creation, by whom
* @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit.
* @link: http://HeuristScholar.org
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @package Heurist academic knowledge management system
* @todo
**/

-->
<html>
	<!-- mini-edit.html

	Copyright 2005 - 2010 University of Sydney Digital Innovation Unit
	This file is part of the Heurist academic knowledge management system (http://HeuristScholar.org)
	mailto:info@heuristscholar.org

	Concept and direction: Ian Johnson.
	Developers: Tom Murtagh, Kim Jackson, Steve White, Steven Hayes,
				Maria Shvedova, Artem Osmakov, Maxim Nikitin.
	Design and advice: Andrew Wilson, Ireneusz Golka, Martin King.

	Heurist is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 3
	of the License, or (at your option) any later version.

	Heurist is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
	even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along with this program.
	If not, see <http://www.gnu.org/licenses/>
	or write to the Free Software Foundation,Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

	-->
 <head>
  <title>Edit record</title>

  <link rel=stylesheet href="../../common/css/global.css">
 </head>

 <body class="popup" width=600 height=400>

  <script src="../../common/js/utilsLoad.js"></script>
  <script src="editRecord.js"></script>
  <script src="../../common/php/displayPreferences.php"></script>

<div id="results"><iframe frameborder=0 class=tab id=edit-frame style="width: 100%; height: 100%;"></iframe></div>
<div id="add_records_footer"><input type=button onClick="window.HEURIST.edit.save();" value="Save record"></div>
  <script>
			if (!window.HEURIST) window.HEURIST = {};
			window.HEURIST.parameters = top.HEURIST.parseParams(location.search);
			window.HEURIST.loadScript(top.HEURIST.basePath +'common/php/loadRecordData.php?recID='+window.HEURIST.parameters['recID']+
											"&db="+top.HEURIST.database.name, true);

			function showRecordProperties() {
				if (! window.HEURIST.edit.record) {
					// We only make it here if someone's screwing around ...
					// It does give a flash of popup window, but it's a bit hard to work around that.
					alert("Sorry - record not found");
					setTimeout(function() { window.close(); }, 0);
					return;
				}
				document.title = "Edit " + window.HEURIST.edit.record.rectype + " record: <i>"+ window.HEURIST.edit.record.title + "</i>";
				// fill in the toolbar fields with the details for this record
//				document.getElementById('rectype-val').innerHTML = '';
//				document.getElementById('rectype-val').appendChild(document.createTextNode(window.HEURIST.edit.record.rectype));

//				document.getElementById('title-val').innerHTML = '';
//				document.getElementById('title-val').appendChild(document.createTextNode(window.HEURIST.edit.record.title));


				loadPublicEditFrame();
			}

			function loadPublicEditFrame() {
				var editFrame = document.getElementById("edit-frame");

				var parameters = window.HEURIST.parameters;
				if (parameters  &&  parameters.recID && parameters.db) {
					editFrame.src = top.HEURIST.baseURL + "records/edit/tabs/publicInfoTab.html?recID=" + parameters.recID + "&db=" + parameters.db;

					editFrame.style.display = "block";
				}

				var defaultClose = window.frameElement.close;
				window.frameElement.close = function() {
					defaultClose(window.HEURIST.edit.record.title, window.HEURIST.edit.record.bdValuesByType);
				};
			}


window.HEURIST.edit = {

	publicHasChanged: false,

	userCanEdit: function() { return true;},
	unchanged: function() {
			window.HEURIST.edit.publicHasChanged = false;
		},

	changed: function() {
			window.HEURIST.edit.publicHasChanged = true;
		},

	save: function() {
		// Attempt to save the public tab

		var editFrame = document.getElementById("edit-frame");
		var contentWindow = editFrame.contentWindow;
		if (contentWindow  &&  window.HEURIST.edit.publicHasChanged) {
			var form = contentWindow.document.forms[0];
			if (form.onsubmit  &&  ! form.onsubmit()) {
				return;	// submit failed ... up to the individual form handlers to display messages
			}

			top.HEURIST.registerEvent(editFrame, "load", function() {
				window.HEURIST.edit.unchanged("public");
				window.HEURIST.edit.save();	// will continue where we left off
			});

			(form.heuristSubmit || form.submit)();
			return;
		}

		// If we get here, there were no unsaved changes.
		// Grab the biblio title from the saved document, and close the window.
		window.close();
	}
};

	top.HEURIST.registerEvent(window, "load", showRecordProperties);

  </script>
 </body>
</html>
